class DefaultData < ActiveRecord::Migration
  def self.up

    sql_create_plperl_diff = <<DOC
    CREATE TYPE diff_type AS (old_word text, new_word text);
    CREATE FUNCTION plperl_diff (text, text) RETURNS diff_type AS $$
    use String::Diff;
    use String::Diff qw(diff); # export functions
    my ($old_word_input ,  $new_word_input) = $_;
    my ($old_word_result, $new_word_result) = String::Diff::diff($old_word_input ,  $new_word_input);
    return {old_word => $old_word_result, new_word => $new_word_result}
    $$ LANGUAGE plperl;
DOC
    CREATE OR REPLACE TYPE diff_type AS (old_word text, new_word text);
    ActiveRecord::Base.establish_connection
	  ActiveRecord::Base.connection.execute(sql_create_plperl_diff)
  end

  def self.down
    ActiveRecord::Base.establish_connection
	  ActiveRecord::Base.connection.execute("DROP FUNCTION plperl_diff")
  end
end